package es.xpt.ysf.commons.issues.view;

import java.io.InputStream;
import java.util.List;

import es.xpt.ysf.YSFException;
import es.xpt.ysf.commons.Names;
import es.xpt.ysf.commons.issues.IssueSearchParams;
import es.xpt.ysf.commons.issues.IssueSession;
import es.xpt.ysf.commons.issues.model.Issue;
import es.xpt.ysf.commons.issues.model.IssueHistory;
import es.xpt.ysf.commons.issues.model.IssueSubscribers;
import es.xpt.ysf.commons.issues.model.IssueValue;
import es.xpt.ysf.commons.issues.model.Issue.IssuePriority;
import es.xpt.ysf.view.LocalDelegate;
import es.xpt.ysf.view.model.UserBean;

public class IssuesDelegate extends LocalDelegate<IssueSession> {

	public IssuesDelegate(UserBean user) {
		super(user);
	}
	
	public boolean addIssue ( Issue issue, String entity, String entityId, String businessArea, IssuePriority priority, Object[] parameters, InputStream jcrData, String jcrDataMimeType ) throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		return ejb.addIssue(issue, entity, entityId, businessArea, priority, parameters, jcrData, jcrDataMimeType);	
	}
	
	public IssueValue getIssue ( String id ) throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		return ejb.getIssue(id);
	}
	
	public void updateIssue ( IssueValue issueValue ) throws YSFException{
		IssueSession ejb = connect(Names.ISSUE);
		ejb.updateIssue(issueValue);
	}
	
	public void addHistoryItem ( String issueId, IssueHistory history ) throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		ejb.addHistoryItem(issueId, history);
	}
	
	public IssueSubscribers getSubscribers ( String businessArea , String relatedUsersEntity ) throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		return ejb.getSubscribers(businessArea, relatedUsersEntity);
	}
	
	public void setSubscribers ( String businessArea, IssueSubscribers subscribers ) throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		ejb.setSubscribers(businessArea, subscribers);
	}
	
	public List<IssueValue> searchIssue ( IssueSearchParams searchParameters ) throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		return ejb.searchIssue(searchParameters);
	}
	
	public List<String> getBusinessAreas() throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		return ejb.getBusinessAreas();
	}
	
	public List<String> getSubscribedRoles() throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		return ejb.getSubscribedRoles();
	}
	
	public List<String> getSubscribedUsers() throws YSFException {
		IssueSession ejb = connect(Names.ISSUE);
		return ejb.getSubscribedUsers();
	}
}
